<template>
  <Select placeholder="请输入车型" :value="value" @on-change="change" :multiple="multiple" filterable clearable remote :remote-method="searchSeries" :loading="searchLoading">
    <Option v-for="(option, index) in seriesOptions" :value="option.value" :key="`vehicle-complete-option-${option.value}`">{{option.label}}</Option>
  </Select>
</template>

<script>
  import {post}  from '@/util/request'

  export default {
    props: ["value",'multiple'],
    data() {
      return {
        seriesVals: [],
        seriesOptions: [],
        searchLoading: false
      }
    },
    methods:{
      change(v){
        this.$emit("input", v);
        this.$emit("on-change", v);
      },
      searchSeries(query){
        if(query !== '') {
          this.searchLoading = true;
          let data = {
            key: query
          };
          post('/common/findVehiclSeriesByBrandIdAndName', data).then(json => {
            this.searchLoading = false;
            if (json.data.sta === 200) {
              this.seriesOptions = json.data.data.map(item => {
                return {
                  value: item.id,
                  label: item.name
                };
              });
            }
          });
        } else {
          this.seriesOptions = [];
        }
      }
    }
  }
</script>
